<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>返回指定的类实现的所有接口。</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.class-implements" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">class_implements</h1>
  <p class="verinfo">(PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">class_implements</span> &mdash; <span class="dc-title">
   返回指定的类实现的所有接口。
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.class-implements-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>class_implements</strong></span>
    ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$class</code></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$autoload</code></span>
  ] ) : <span class="type">array</span></div>

  <p class="para rdfs-comment">
   本函数返回一个数组，该数组中包含了指定类<code class="parameter">class</code>及其父类所实现的所有接口的名称。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.class-implements-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">class</code></dt>

     <dd>

      <p class="para">
        对象（类实例）或字符串（类名称）。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">autoload</code></dt>

     <dd>

      <p class="para">
      是否允许使用<a href="language.oop5.autoload.html" class="link">__autoload</a>
      魔术函数来自动装载该类。默认值为<strong><code>TRUE</code></strong>。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>



 <div class="refsect1 returnvalues" id="refsect1-function.class-implements-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   调用成功则返回一个数组，否则返回<strong><code>FALSE</code></strong>。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.class-implements-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.1.0</td>
       <td>
        增加了允许参数<code class="parameter">class</code>为字符串的选项。增加了<code class="parameter">autoload</code>参数。
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.class-implements-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4713">
    <p><strong>Example #1 <span class="function"><strong>class_implements()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">interface&nbsp;</span><span style="color: #0000BB">foo&nbsp;</span><span style="color: #007700">{&nbsp;}<br />class&nbsp;</span><span style="color: #0000BB">bar&nbsp;</span><span style="color: #007700">implements&nbsp;</span><span style="color: #0000BB">foo&nbsp;</span><span style="color: #007700">{}<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">class_implements</span><span style="color: #007700">(new&nbsp;</span><span style="color: #0000BB">bar</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">//&nbsp;since&nbsp;PHP&nbsp;5.1.0&nbsp;you&nbsp;may&nbsp;also&nbsp;specify&nbsp;the&nbsp;parameter&nbsp;as&nbsp;a&nbsp;string<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">class_implements</span><span style="color: #007700">(</span><span style="color: #DD0000">'bar'</span><span style="color: #007700">));<br /><br /><br />function&nbsp;</span><span style="color: #0000BB">__autoload</span><span style="color: #007700">(</span><span style="color: #0000BB">$class_name</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;require_once&nbsp;</span><span style="color: #0000BB">$class_name&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">'.php'</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;use&nbsp;__autoload&nbsp;to&nbsp;load&nbsp;the&nbsp;'not_loaded'&nbsp;class<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">class_implements</span><span style="color: #007700">(</span><span style="color: #DD0000">'not_loaded'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Array
(
    [foo] =&gt; foo
)

Array
(
    [interface_of_not_loaded] =&gt; interface_of_not_loaded
)
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.class-implements-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="class_parents.html" class="function" rel="rdfs-seeAlso">class_parents()</a> - 返回指定类的父类。</span></li>
    <li class="member"><span class="function"><a href="get_declared_interfaces.html" class="function" rel="rdfs-seeAlso">get_declared_interfaces()</a> - 返回一个数组包含所有已声明的接口</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>